module windump.singleton;

final class SingletonHolder(T)
{
    private static T m_instance;

    private this(){};

    static this()
    {        
        static if(!is(T == class) || !is(T == struct) || !is(T == union))
            static assert("Invalid type of T");

        static if(is(T == class))
            m_instance = new T();
    }

    private static ~this()
    {
//        static if(is(T == class))
//            delete m_instance;
//        m_instance = null;
    }

    public static T instance()
    in
    {
        assert(!(m_instance is null));
    }
    body
    {
        return m_instance;
    }

    public static T opCall()
    {
        return instance();
    }

}

